<template>
	<view>
		<u-cell-group>
			<u-cell-item icon="setting-fill" title="温度:">
				<u-line-progress :striped="true" :percent="tmpe" :striped-active="true"></u-line-progress>
			</u-cell-item>
			<u-cell-item icon="integral-fill" title="湿度:">
				<u-line-progress :striped="true" :percent="humi" :striped-active="true"></u-line-progress>
			</u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tmpe:'',
				humi:'',
				timer:'',
			}
		},
		methods: {

		},
		onLoad() {
			// 创建一个get请求向后台发送数据，每一秒钟请求一次
			this.timer = setInterval(()=>{
				uni.request({
					url:"http://localhost:8080/test",
					method:"GET",
					success:(res) =>{
						var mydata = res.data.data[0];
						console.log(mydata);
						var humi = parseFloat(mydata.humi);
						var tmpe = parseFloat(mydata.tmpe);
						this.humi = humi.toFixed(2);
						this.tmpe = tmpe.toFixed(2);
					}
				})
			},1000)
		},
		beforeDestroy() {
			clearInterval(this.timer)
		}
	}
</script>

<style>

</style>
